package com.sxpi.chapter01;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @Author: 董伟豪
 * @Date: 2023/2/6 14:02
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Prototype implements Cloneable {

    private String name;

    /**
     * 如果想要深拷贝的话，这个里面也必须实现Cloneable接口
     */
    private Address address;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Prototype prototype = (Prototype) super.clone();
        // 这里要把引用的全部拷贝，这里会破坏开辟原则
        prototype.address = (Address) address.clone();
        return prototype;
    }
}
